﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MCB.Trading.Generic;
using System.Threading;

namespace MCB.Trading.Test.Market
{
    public class Order<TProduct> : IOrder<string, TProduct>
    {
        public Order(SideEnum side, TProduct product, int value, int volume = 1)
        {
            _side = side;
            Product = product;
            Value = value;
            Volume = volume;
        }

        protected SideEnum _side;

        protected string _id;

        public string Id
        {
            get
            {
                if (string.IsNullOrEmpty(_id))
                {
                    lock (this)
                    {
                        if (string.IsNullOrEmpty(_id))
                            _id = string.Concat(Thread.CurrentThread.ManagedThreadId, DateTime.Now.Millisecond);
                    }
                }
                return _id;
            }
        }

        public TProduct Product { get; set; }

        object IOrder.Id
        {
            get { return Id; }
        }

        public SideEnum Side
        {
            get { return _side; }
        }

        public int Volume { get; set; }
        public int Value { get; set; }
        public bool TopOfBook { get; set; }

        object IOrder.Product
        {
            get { return Product; }
        }
    }
}
